<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue-2.4.0.js"></script>
    <script src="../js/vue-resource-1.3.4.js"></script>
    <link rel="stylesheet" href="../css/bootstrap-3.3.7.css">
</head>

<body>
    <div id="app">
        <div>

            <label>
                name:
                <input type="text" v-model="name" @keyup.13="na">
            </label>
            <input type="button" value="添加" >
        </div>
        <table class="table table-bordered table-hover table-striped">
            <thead>
                <tr>
                    <th>Id</th>
                    <th>Name</th>
                    <th>Ctime</th>
                    <th>Operation</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in list" :key="item.id">
                    <td>{{item.id}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.ctime | datasert()}}</td>
                    <td><a href="" @click.prevent="del(item.id)">删除</a></td>
                </tr>
            </tbody>
        </table>

    </div>
</body>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            name:'',
            list: [{
                    id: 1,
                    name: '奔驰',
                    ctime: new Date()
                },
                {
                    id: 2,
                    name: '宝马',
                    ctime: new Date()
                }
            ]
        },
        created(){
 this.getAllList()
        },
        methods:{
            na(){},
            getAllList(){
                this.$http.get('http://vue.studyit.io/api/getprodlist').then(result=>{
                       if(result.status === 0){
                this.list = result.message
                       }else{
                           alert('获取数据失败')
                       }
                }) 
            }
        }
    })
</script>

</html>